package com.xand.bt.terminal.btce.connector.market;

import java.util.logging.Level;

import com.xand.bt.terminal.common.util.NumberHelper;

public class MarketLevel implements Comparable<MarketLevel> {

	public static final int DIRECTION_ASK = 0;
	public static final int DIRECTION_BID = 1;
	
	private long price;
	
	private long volume;
	
	private int direction;
	
	private String reference;
	
	public MarketLevel(String reference, long price, long volume, int direction) {
		
		this.reference = reference;
		this.price = price;
		this.volume = volume;
		this.direction = direction;
		
	}

	public void setVolume(long volume) {
		this.volume = volume;
	}
	
	public String getReference() {
		return this.reference;
	}
	
	public long getPrice() {
		return price;
	}

	public long getVolume() {
		return volume;
	}

	public int getDirection() {
		return this.direction;
	}

	public String toString() {
		
		StringBuilder ret = new StringBuilder("MarketLevel - [");
		
		ret.append("reference=");
		ret.append(reference);
		ret.append(";");
		
		String sDirection = "";
		if(this.direction == DIRECTION_ASK) {
			sDirection = "ASK";
		}else{
			sDirection = "BID";
		}
		
		ret.append("direction=");
		ret.append(sDirection);
		ret.append(";");
		
		ret.append("price=");
		ret.append(NumberHelper.formatLong(this.price, 1000000, 6));
		ret.append(";");
		
		ret.append("volume=");
		ret.append(NumberHelper.formatLong(this.volume, 100000000, 8));
		
		ret.append("]");
		
		return ret.toString();
	}
	
	public int compareTo(MarketLevel test) {
		
		int ret = 0;
		
		if(direction == DIRECTION_ASK) {
			
			if(test.getPrice() > this.price) {
				ret = -1;
			}else{
				ret = 1;
			}
			
		} else {
			
			if(test.getPrice() > this.price) {
				ret = 1;
			}else{
				ret = -1;
			}
			
		}
		
		return ret;
	}
	
}
